<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <ui:composition template="/template/DefaultTemplate.xhtml">
         
        <ui:define name="content">
             <br />
             <h:form>
                <p:panel toggleable="true" id="order" header="Back Order Information">
                    <h:panelGrid columns="2">
                    <h:outputLabel value="Back Order Status :" for="status" />
                    <h:outputText  value="#{backorderEntityController.selected.status}" style="color:green"/>
                    <h:outputLabel value="Back Order Required Delivery Date :" for="requiredLeadTime" />
                    <h:outputText  value="#{backorderEntityController.formatter.format(backorderEntityController.selected.requiredLeadTime)}"/>
                    </h:panelGrid>
                    
                    <br />
                        <p:dataTable value="#{backorderEntityController.selected.productQuantityPriceList}" 
                                     var="item" style="text-align: center"
                                     paginator="true" rows="15"  
                                     paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                     rowsPerPageTemplate="5,10,15">
                            
                            <p:column filterBy="#{item.product.productName}">
                                <f:facet name="header">
                                    <h:outputText value="Product Name"/>
                                </f:facet>
                                <h:outputText value="#{item.product.productName}"/>
                            </p:column> 
                            
                            <p:column filterBy="#{item.quantity}">
                                <f:facet name="header">
                                    <h:outputText value="Quantity (Cases)"/>
                                </f:facet>
                                <h:outputText value="#{item.quantity}"/>
                            </p:column>      
                             </p:dataTable>   
                   
                    
                </p:panel>
             </h:form>
                <br/>
                <h:form>
                <p:panel header="MRP Update" id="lalala" toggleable="true" rendered="#{!backorderEntityController.selected.updatedAtpMrps.isEmpty()}">

                    <h:panelGroup id="messagePane2" layout="block">
                        <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
                    </h:panelGroup>
                    
                    
                   
                    <h:panelGroup rendered="#{backorderEntityController.selected.isMrpUpdated==true}">>
                        
                        <br />
                        <p:dataTable value="#{backorderEntityController.selected.updatedAtpMrps}" 
                                     var="item" style="text-align: center"
                                     paginator="true" rows="15"  
                                     paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                     rowsPerPageTemplate="5,10,15">
                            
                            <p:column filterBy="#{item.mrp.rawMaterial.productName}">
                                <f:facet name="header">
                                    <h:outputText value="RawMaterial Name"/>
                                </f:facet>
                                <h:outputText value="#{item.mrp.rawMaterial.productName}"/>
                            </p:column> 
                            
                            <p:column filterBy="#{item.mrp.yearOfProduction}">
                                <f:facet name="header">
                                    <h:outputText value="Year"/>
                                </f:facet>
                                <h:outputText value="#{item.mrp.yearOfProduction}"/>
                            </p:column>      
                            
                            <p:column filterBy="#{item.mrp.monthOfProduction}">
                                <f:facet name="header">
                                    <h:outputText value="Month"/>
                                </f:facet>
                                <h:outputText value="#{item.mrp.monthOfProduction}"/>
                            </p:column> 
                            
                             <p:column filterBy="#{item.mrp.weekOfProduction}">
                                <f:facet name="header">
                                    <h:outputText value="Week"/>
                                </f:facet>
                                <h:outputText value="#{item.mrp.weekOfProduction}"/>
                            </p:column> 
                            
                            <p:column filterBy="#{item.mrp.plannedOrderQuantity}">
                                <f:facet name="header">
                                    <h:outputText value="Old Planned Orders(Kg/l)" rendered="#{backorderEntityController.selected.isMrpUpdated==false}"/>
                                    <h:outputText value="Updated Planned Orders(Kg/l)" rendered="#{backorderEntityController.selected.isMrpUpdated==true}"/>
                                </f:facet>
                                <h:outputText value="#{item.mrp.plannedOrderQuantity}" style="color:green"/>
                            </p:column>
                            
                            <p:column filterBy="#{item.quantity}" rendered="#{backorderEntityController.selected.isMrpUpdated==false}">
                                <f:facet name="header">
                                    <h:outputText value="Recommended new Orders(Kg/l)" />
                                </f:facet>
                                <h:inputText value="#{item.quantity}" style="color:green"/>
                            </p:column>
                            
                           
                            
                            

                           
                        </p:dataTable>   
                        
                       
                    </h:panelGroup>
                    
                    <br />
               
            </p:panel>
                 </h:form> 
            <br/>
            <p:panel header="ATP Result" id="ATPResult" toggleable="true" rendered="#{backorderEntityController.selected.mrpCheckStatus!=null}">
                <h:form prependId="false">
                    <h:panelGroup id="messagePanel" layout="block">
                        <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
                    </h:panelGroup>
                    
                    <h:panelGrid columns="2">
                    
                    <h:outputLabel value="Last ATP done for this Back Order :" for="lastModified" />
                    <h:outputText  value="#{backorderEntityController.formatter.format(backorderEntityController.selected.lastModifiedAt)}"/>
                    <h:outputLabel value="MRP Check Result :" for="mrpResult" />
                    <h:outputText  value="#{backorderEntityController.selected.mrpCheckStatus}" style="color: #D20005"/>
                     <h:outputLabel value="MRP earliest fulfillment date given :"  />
                    <h:outputText  value="#{backorderEntityController.formatter.format(backorderEntityController.selected.earliestMrpFulfillmentDate)}" style="color:seagreen"/>
                    <h:outputLabel value="Confirmed lead time given :"  />
                    <h:outputText  value="#{backorderEntityController.formatter.format(backorderEntityController.selected.confirmedLeadTime)}" style="color:seagreen"/>
                    </h:panelGrid>
                   
                    <h:panelGroup rendered="#{backorderEntityController.selected.failedAtpMrps.size()>0}">>
                        <h:panelGrid columns="1">
                        <h:outputText value="The following MRPs could not meet the increase in requirement !" style="color: #D20005"/>
                        </h:panelGrid>
                        <br />
                        <p:dataTable value="#{backorderEntityController.selected.failedAtpMrps}" 
                                     var="item" style="text-align: center"
                                     paginator="true" rows="15"  
                                     paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                     rowsPerPageTemplate="5,10,15">
                            
                            <p:column filterBy="#{item.mrp.rawMaterial.productName}">
                                <f:facet name="header">
                                    <h:outputText value="RawMaterial Name"/>
                                </f:facet>
                                <h:outputText value="#{item.mrp.rawMaterial.productName}"/>
                            </p:column> 
                            
                            <p:column filterBy="#{item.mrp.yearOfProduction}">
                                <f:facet name="header">
                                    <h:outputText value="Year"/>
                                </f:facet>
                                <h:outputText value="#{item.mrp.yearOfProduction}"/>
                            </p:column>      
                            
                            <p:column filterBy="#{item.mrp.monthOfProduction}">
                                <f:facet name="header">
                                    <h:outputText value="Month"/>
                                </f:facet>
                                <h:outputText value="#{item.mrp.monthOfProduction}"/>
                            </p:column> 
                            
                             <p:column filterBy="#{item.mrp.weekOfProduction}">
                                <f:facet name="header">
                                    <h:outputText value="Week"/>
                                </f:facet>
                                <h:outputText value="#{item.mrp.weekOfProduction}"/>
                            </p:column> 
                            
                            <p:column filterBy="#{item.quantity}">
                                <f:facet name="header">
                                    <h:outputText value="Short Fall(Kg/l)" />
                                </f:facet>
                                <h:outputText value="#{item.quantity}" style="color: #D20005"/>
                            </p:column>
                            
                            
<!--                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="&nbsp;"/>
                                </f:facet>
                                <p:menuButton value="Options" >
                                     <p:menuitem value=" ATP check" ajax="false" icon="ui-icon ui-icon-search" 
                                                action="#{backorderEntityController.atpCheck}" rendered="#{item.archived==false and loginBacking.editBackOrder}"/>  
                               
                                     <p:menuitem value=" Delete" ajax="false" rendered="#{item.archived==false and loginBacking.deleteSalesForecast}" icon="ui-icon ui-icon-close"
                                                action="#{expectedYearOnYearGrowthEntityController.destroy}"/> 
                                </p:menuButton>
                                
                            </p:column>-->
                           
                        </p:dataTable>   
                    </h:panelGroup>
                    <br />
                </h:form>
            </p:panel>
             
            <h:form>
            <p:commandButton value="Back" action="#{backorderEntityController.prepareList}" />
            <p:commandButton value=" Approve"  rendered="#{loginBacking.editBackOrder and item.mrpCheckStatus!=null }" 
                                                action="#{backorderEntityController.approveAtp(item)}"/> 
            </h:form>
        </ui:define>
    </ui:composition>

</html>
